package com.ql.controller.menzhen;

import com.alibaba.fastjson.JSON;
import com.ql.pojo.menzhen.Doctor;
import com.ql.pojo.menzhen.User;
import com.ql.pojo.user.Keshi;
import com.ql.service.keshi.KeShiService;
import com.ql.service.menzen.FomularyService;
import com.utils.OrderIdByTime;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.lang.reflect.Member;
import java.util.Enumeration;
import java.util.List;

@Controller
@RequestMapping("/guahao/")
public class guahao {

    @Resource
    public KeShiService keShiService;

    @Resource
    public FomularyService fomularyService;

    @RequestMapping(value = "keshi", produces = "application/json; charset=utf-8")
    @ResponseBody
    public String keshi(Model model){

        List<Keshi> allKeShi = keShiService.getAllKeShi();

        return JSON.toJSON(allKeShi).toString();
    }

//    @RequestMapping("doctor")
//    public String doctor(@RequestParam("department") int kid,Model model){
//        List<Doctor> doctors = ;
//        model.addAttribute("",doctors);
//        return "forward:../qiantai/html/zuche/guahao.jsp";
//    }
    @RequestMapping(value = "doctor")
    public String checkMember(@RequestParam("department") int kid,Model model) {
        List<Doctor> doctors = fomularyService.getByIdDoctor(kid);
//            attr.addAttribute("doctors",doctors) ;
//        System.out.println(doctors.toString());
        model.addAttribute("doctors",doctors);
        return "forward:../qiantai/html/zuche/keshi2.jsp";
    }

    @RequestMapping("yuyue")
    public String yuyue(@RequestParam("docId")int docId,Model model){
        Doctor doctor = fomularyService.getDoctor(docId);
        model.addAttribute("doctor",doctor);
        return "forward:../qiantai/html/zuche/keshi3.jsp";
    }

    @RequestMapping("zhifu")
    public String zhifu(@RequestParam("docId")int docId,
                        @RequestParam("department")int department,
                        Model model,
                        HttpSession httpSession){
        String orderId = OrderIdByTime.getOrderIdByTime();
        Doctor doctor = fomularyService.getDoctor(docId);
        double money = 25;
        User user =(User) httpSession.getAttribute("userSession");
//        model.addAttribute();
//        model.addAttribute();
//        model.addAttribute();
//        model.addAttribute();
//        model.addAttribute();
        httpSession.setAttribute("guahaodanId",orderId+user.getUserId());
        httpSession.setAttribute("userId",user.getUserId());
        httpSession.setAttribute("department",department);
        httpSession.setAttribute("doctorId",doctor.getDocId());
        httpSession.setAttribute("Kno",doctor.getDepartment());
        httpSession.setAttribute("money",money);
        return "forward:../qiantai/html/zuche/keshi4.jsp";
    }

}
